package huawei.widget;

import android.content.Context;
import android.os.Build.VERSION;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.widget.TextView.BufferType;

public class HwButton extends HwTextView {
    public HwButton(Context context) {
        this(context, null);
    }

    public HwButton(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwButton(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        if (getMaxLines() == 1 && VERSION.SDK_INT < 21) {
            setSingleLine();
        }
    }

    public boolean isAllCaps() {
        TransformationMethod transformationMethod = getTransformationMethod();
        return transformationMethod != null && transformationMethod.getClass().getName().equals("android.text.method.AllCapsTransformationMethod");
    }

    public void setText(CharSequence charSequence, BufferType bufferType) {
        if (isAllCaps()) {
            charSequence = getTransformationMethod().getTransformation(charSequence, this);
        }
        super.setText(charSequence, bufferType);
        requestLayout();
        invalidate();
    }
}
